import React, { Component } from 'react'
import request from '../../util/request'
import {IProduct} from '../../types/product'
import PItem from '../../component/p-item/p-item'

interface IProps{
    match:any
}

interface IState{
    productList:IProduct[]
}

class ProductList extends Component<IProps,IState>{
    state = {
        productList:[]
    }

    componentDidMount(){
        //获取商品列表
        request.get('/api/product',{id:this.props.match.params.id}).then(res => {
            this.setState({
                productList:res.data.data
            })
        })
    }
   
    render() {
        let {productList} = this.state;
        return (
            <div>
                {productList.length && productList.map((item:IProduct) => <PItem key={item.id} item={item}></PItem>)}
            </div>
        )
    }
}

export default ProductList
